home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / library / ix_exec_entry.c < prev    next >
C/C++ Source or Header  |  1995-12-23  |  4KB  |  139 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  ix_exec_entry.c,v 1.1.1.1 1994/04/04 04:30:55 amiga Exp
  20.  *
  21.  *  ix_exec_entry.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:55  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.3  1992/08/09  20:47:19  amiga
  26.  *  call main thru exit, or no atexit handlers will be called!
  27.  *
  28.  *  Revision 1.2  1992/07/04  19:13:42  mwild
  29.  *  add SIGWINCH handler installation/removal
  30.  *
  31.  * Revision 1.1  1992/05/14  19:55:40  mwild
  32.  * Initial revision
  33.  *
  34.  */
  35.  
  36. #define KERNEL
  37. #include "ixemul.h"
  38. #include "kprintf.h"
  39. #include <sys/wait.h>
  40. #include <string.h>
  41.  
  42. int
  43. ix_exec_entry (int argc, char **argv, char **environ, int *real_errno, 
  44.            int (*main)(int, char **, char **))
  45. {
  46.   volatile struct Process *me = (struct Process *) SysBase->ThisTask;
  47.  
  48.   /* we're coming from another process here, either after vfork() or from a
  49.    * process that wants to `replace' itself with this program. Thus the fpu
  50.    * is probably already initialized to some bogous state. That's why we
  51.    * HAVE to restore it into a default state here. */
  52.  
  53.   if (gotanfpu())
  54.     resetfpu();
  55.  
  56.   if (is_ixconfig(argv[0]))
  57.     {
  58.       u.p_xstat = W_EXITCODE(10, 0);
  59.       return u.p_xstat;
  60.     }
  61.  
  62.   /* a program started by ix_exec_entry() must have some ix'like shell
  63.      around, that takes care of printing exit-states, so don't print them
  64.      again in sig_exit() */
  65.   u.u_argline = 0;
  66.   u.u_arglinelen = 0;
  67.   
  68.   if (real_errno)
  69.     u.u_errno = real_errno;
  70.  
  71.   KPRINTF (("&errno = %lx\n", real_errno));
  72.  
  73.   if (!_setjmp (u.u_jmp_buf))
  74.     {
  75.       /* install the signal mask that was active before execve() was called */
  76.       syscall (SYS_sigsetmask, u.u_oldmask);
  77.  
  78.       /* this is not really the right thing to do, the user should call
  79.          ix_get_vars2 () to initialize environ to the address of the variable
  80.          in the calling program. However, this setting guarantees that 
  81.          the user area entry is valid for getenv() calls. */
  82.       u.u_environ = &environ;
  83.  
  84.       ix_install_sigwinch ();
  85.  
  86.       /* If this process is traced (under debugger control)
  87.      then cause a sigtrap.  */
  88.       if (u.p_flag & STRC)
  89.     {
  90.       KPRINTF(("ix_exec_entry(): STRC: _psignal (me=%lx, SIGTRAP);\n", me));
  91.  
  92.       _psignal ((struct Task *) me, SIGTRAP);
  93.  
  94.       /* The handler for hardware traps has now been told to expect this trap
  95.          (specialized signal handler called from sig_launch()), and will
  96.          just stop the process, and increment the PC over this instruction.  */
  97.       asm (" trap #0");
  98.  
  99. #if 0
  100.       {
  101.         u_int curr_disp;
  102.  
  103.         /* _psignal() SHOULD have ensured the context switch, but... */
  104.         for (curr_disp = SysBase->DispCount; curr_disp == SysBase->DispCount; )
  105.           ;
  106.       }
  107. #endif
  108.       
  109.       /* A context switch is guaranteed to have taken place at this time,
  110.          since we signalled ourselves.  As we are continuing now, it means
  111.          the debugger process has told us to continue.  */
  112.       KPRINTF(("ix_exec_entry(): STRC: continuing after _psignal (me=%lx, SIGTRAP);\n", me));
  113.     }
  114.       /* the first time thru call the program */
  115.       exit (main (argc, argv, environ));
  116.       /* not reached! */
  117.     }
  118.   /* we came from a longjmp-call */
  119.  
  120.   ix_remove_sigwinch ();
  121.  
  122.   return u.p_xstat;
  123. }
  124.  
  125. /* ixconfig is no longer supported and can actually crash ixemul, so
  126.    abort if the user tries to start ixconfig. */
  127. int is_ixconfig(char *prog)
  128. {
  129.   int len;
  130.  
  131.   if ((len = strlen(prog)) <= 8 || strchr("/:", prog[len - 9]))
  132.     if (len >= 8 && !stricmp(&prog[len - 8], "ixconfig"))
  133.       {
  134.         ix_panic("Please use ixprefs instead of ixconfig!");
  135.         return 1;
  136.       }
  137.   return 0;
  138. }
  139.